import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import sourceMaps from 'rollup-plugin-sourcemaps'
import camelCase from 'lodash.camelcase'
import typescript from 'rollup-plugin-typescript2'
import json from 'rollup-plugin-json'
import builtins from 'rollup-plugin-node-builtins';
import globals from 'rollup-plugin-node-globals';

const pkg = require('./package.json')

const libraryName = 'iwe9'

export default {
  input: `src/${libraryName}.ts`,
  output: [
    {
      file: pkg.main,
      name: camelCase(libraryName),
      format: 'commonjs',
      sourcemap: true,
      globals: {
        rxjs: "Rx"
      }
    }
  ],
  // Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash')
  external: [
    "ws",
    "@nestjs/common",
    "@nestjs/core",
    "@nestjs/microservices",
    "@nestjs/graphql",
    "@nestjs/typeorm",
    "@nestjs/websockets",
    "typeorm",
    "crypto-js",
    "graphql-tools",
    "graphql",
    "rxjs",
    "rxjs/operators",
    "fs",
    "path",
    "os",
    "xml2js",
    "dgram",
    "child_process",
    "express",
    "socket.io",
    "path",
    "ejs"
  ],
  watch: {
    include: 'src/**',
  },
  plugins: [
    globals(),
    builtins(),
    // Allow json resolution
    json(),
    // Compile TypeScript files
    typescript({ useTsconfigDeclarationDir: true }),
    // Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs)
    commonjs(),
    // Allow node_modules resolution, so you can use 'external' to control
    // which external modules to include in the bundle
    // https://github.com/rollup/rollup-plugin-node-resolve#usage
    resolve(),
    // Resolve source maps to the original source
    sourceMaps(),
  ],
}
